use tokio::task;
use reqwest::Client;
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
use flume::{Sender, Receiver, bounded};
use futures::stream::{FuturesUnordered, StreamExt};
use std::time::Instant;



// 发送请求并判断是否成功
pub async fn send_requests_for_duration(
    rx: Receiver<reqwest::Request>,
    total_counter: Arc<AtomicUsize>,
    success_counter: Arc<AtomicUsize>,
    client: Arc<Client>
) {
    while let Ok(req) = rx.recv_async().await {
        let client = client.clone();
        let total_counter = total_counter.clone();
        let success_counter = success_counter.clone();
        tokio::spawn(async move {
            total_counter.fetch_add(1, Ordering::SeqCst);
            let response = client.execute(req).await;
            if response.is_ok() {
                success_counter.fetch_add(1, Ordering::SeqCst);
            }
            // println!("Consumer {} sent a request", id);
        });
    }
}